package com.lg.cms.controller.admin.work;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lg.cms.entity.Article;
import com.lg.cms.entity.Comment;
import com.lg.cms.entity.SuperUser;
import com.lg.cms.service.ArticleService;
import com.lg.cms.service.CommentService;
import com.lg.cms.utils.StatsUtil;
import com.lg.cms.utils.SubjectUtil;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description: 工作台
 * @Author: wuyuhang
 * @create: 2020-10-08 17:38
 */
@Controller
@RequestMapping("/admin")
public class WorkController {

    @Autowired
    ArticleService articleService;
    @Autowired
    CommentService commentService;
    @Resource
    StatsUtil statsUtil;

    @GetMapping("/")
    public String get(Model model, HttpServletRequest request){
        model.addAttribute("user", SubjectUtil.getSuperUser());
        model.addAttribute("request", request);
        //文章数量
        model.addAttribute("articleCount", articleService.list(
                new QueryWrapper<Article>().eq("state", true)).size());
        //评论数量
        model.addAttribute("commentCount", commentService.list(
                new QueryWrapper<Comment>().eq("`check`", true)).size());
        //访问量(当天)
        model.addAttribute("currentVisits", statsUtil.getAllViewNum());
        //跳出率...

        return "/admin/index/index";

    }
    @GetMapping("/test")
    public String test(Model model,HttpServletRequest request){
        model.addAttribute("request",request);
        return "admin/index/test";

    }
}